package com.student;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Arrays;

public class TCPClient {
	
	public static void main(String[] args) {
		try {
			Socket client = new Socket("192.168.31.10", 1000);
			System.out.println("链接上了服务器");
			OutputStream out = client.getOutputStream();
			out.write(new byte[] {1,2,3,4,5});
			out.flush();
			System.out.println("发送了一段字节数组");

			InputStream in=client.getInputStream();
			byte[] bs=new byte[15];
			int len = in.read(bs);
			System.out.println("接收一段客户端的字节数组：" + len + "=" + Arrays.toString(bs));
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
